 <!DOCTYPE html>
 <html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
 </head>
 <body>
  <script>

    // 1. 在ES5以及之前,只有全局和函数会形成自己的作用域
    // 代码块
    function foo(){
      console.log("Hello World")
    }

    {
      var message = "Hello World"
    }
    console.log(message)

    // 2. 从ES6开始,使用let/const/function/class声明的变量是有块级作用域
    {
      let age = 18
      const height = 1.88
      class Person{}
      function foo(){
        console.log("foo function")
      }
    }
    // console.log(age)//age is not defined
    // console.log(height)//height is not defined
    // const p = new Person() // Person is not defined
    foo() // 正常执行

  </script>
 </body>
 </html>